package com.kevin.shop.controller;

import java.util.List;
import java.util.Set;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kevin.shop.domain.entity.ShopGoodSelection;
import com.kevin.shop.service.IShopGoodSelectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 选品Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/shop/selection")
public class ShopGoodSelectionController extends BaseController
{
    @Autowired
    private IShopGoodSelectionService shopGoodSelectionService;

    /**
     * 查询选品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoodSelection shopGoodSelection)
    {
        startPage();
        List<ShopGoodSelection> list = shopGoodSelectionService.selectShopGoodSelectionList(shopGoodSelection);
        return getDataTable(list);
    }

    /**
     * 导出选品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:export')")
    @Log(title = "选品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopGoodSelection shopGoodSelection)
    {
        List<ShopGoodSelection> list = shopGoodSelectionService.selectShopGoodSelectionList(shopGoodSelection);
        ExcelUtil<ShopGoodSelection> util = new ExcelUtil<ShopGoodSelection>(ShopGoodSelection.class);
        util.exportExcel(response, list, "选品数据");
    }

    /**
     * 获取选品详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:query')")
    @GetMapping(value = "/{selectionId}")
    public AjaxResult getInfo(@PathVariable("selectionId") Long selectionId)
    {
        return success(shopGoodSelectionService.selectShopGoodSelectionBySelectionId(selectionId));
    }

    /**
     * 新增选品
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:add')")
    @Log(title = "选品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopGoodSelection shopGoodSelection)
    {
        return toAjax(shopGoodSelectionService.insertShopGoodSelection(shopGoodSelection));
    }

    /**
     * 新增选品
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:add-batch')")
    @Log(title = "选品", businessType = BusinessType.INSERT)
    @PostMapping("/add-batch")
    public AjaxResult addBatch(@NotEmpty @RequestBody Set<String> goods)
    {
        return toAjax(shopGoodSelectionService.addBatch(goods));
    }

    /**
     * 修改选品
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:edit')")
    @Log(title = "选品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopGoodSelection shopGoodSelection)
    {
        return toAjax(shopGoodSelectionService.updateShopGoodSelection(shopGoodSelection));
    }

    /**
     * 删除选品
     */
    @PreAuthorize("@ss.hasPermi('shop:selection:remove')")
    @Log(title = "选品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{selectionIds}")
    public AjaxResult remove(@PathVariable Long[] selectionIds)
    {
        return toAjax(shopGoodSelectionService.deleteShopGoodSelectionBySelectionIds(selectionIds));
    }
}
